/*
 *  XMLNode.h
 *  cactus-xml
 *
 *  Created by Yury Nikalayuk on 02.04.10.
 *  Copyright 2011 CactusSoft. All rights reserved.
 *
 */
#include <string>
#include <map>
#include <vector>

class XMLValue
{
public:
	XMLValue();
	XMLValue(const std::string &_value);
	
	const std::string & AsString() const;
	int AsInt(int defaultValue = 0) const;
	double AsDouble(double defaultValue = 0) const;
	bool AsBool(bool defaultValue = false) const;
	
private:
	std::string value;
};

class XMLNode
{
	friend class ParsedXML;
	
public:
	typedef std::map<std::string, XMLValue> XMLAttributes;
	typedef std::vector<std::string> Names;
	typedef std::vector<XMLNode*> XMLNodes;
	
	XMLNode();
	~XMLNode();
	
	const std::string & Name() const;
	const XMLValue & Value() const;
	Names GetAttributes() const;
	
	const XMLNode & Child(const std::string &key) const;
	const XMLNode & operator[](const std::string &key) const;
	const XMLNodes & Children() const;
	
	int IntValue(int defaultValue = 0) const;
	double DoubleValue(double defaultValue = 0) const;
	bool BoolValue(bool defaultValue = false) const;
	const std::string & StringValue() const;
	
	const XMLValue & Attribute(const std::string &key) const;
	
private:
	std::string name;
	XMLValue value;
	XMLAttributes attributes;
	XMLNodes children;
	
	typedef std::map<std::string, XMLNode*> XMLNodesMap;
	XMLNodesMap childrenMap;
	
	//private copy constructor
	XMLNode(const XMLNode &node);
};